package com.hmall.item.web;

import com.hmall.common.pojo.PageDTO;
import com.hmall.item.dto.Pageddttoo;
import com.hmall.item.dto.RealmePhone;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;

    @GetMapping("/list")
    public PageDTO PageQuery(Pageddttoo pageddttoo) {
        PageDTO pageDTO=  itemService.PagedQuery(pageddttoo);
        return pageDTO;

    }
    @GetMapping("/{id}")
    public Item selectbyid(@PathVariable Long id){
        return itemService.selectbyid(id);
    }
    @PostMapping
    public void  insert(@RequestBody RealmePhone realmePhone){
        itemService.insert(realmePhone);
    }
    @PutMapping
    public void uptate(@RequestBody RealmePhone realmePhone){
        itemService.update(realmePhone);
    }
    @PutMapping("/status/{id}/{status}")
    public void updateStatus(@PathVariable Long id,@PathVariable Integer status){
        itemService.updateStatus(id,status);
    }
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id){
        itemService.delete(id);
    }
    @PutMapping("/stock/{itemId}/{num}")
    public void updateStock(@PathVariable Long itemId,@PathVariable Integer num){
        itemService.updateStock(itemId,num);
    }
}
